from numpy import *
from pandas import DataFrame, Series
import pandas as pd
import numpy as np
import pylab as pl
import json

path = 'D:\\mine\\pydata-book-master\\ch02\\usagov_bitly_data2012-03-16-1331923249.txt'

records = [json.loads(line) for line in open(path)]
# tzs = [record['tz'] for record in records if 'tz' in record]

frame = DataFrame(records)
# tz_counts = (frame['tz'].value_counts())[:10]
# print(tz_counts)

# 补充缺失数据
clean_tz = frame['tz'].fillna('Missing')
clean_tz[clean_tz == ''] = 'Unknown'
tz_counts = (clean_tz.value_counts())[:10]
print(tz_counts)

# pl.hist(tz_counts)
# pl.show()
tz_counts.plot(kind='bar', rot=0)
